<template>
  <div class="homeswiper">
    <swiper class="my-swipe" :options="bannerSwi" indicator-color="#E48B2C">
      <swiper-slide v-for="(item, index) in banner" :key="index">
        <img :src="item.pic" :alt="item.name" @click="viewDetail(item.url)" />
      </swiper-slide>
    </swiper>
    <div class="panel-paginationh" slot="pagination"></div>

    <div class="loginBox">
      <div class="login right">
        <div class="weclome" :class="$store.state.access_token ? 'isLoad' : ''">
          <img src="~assets/images/customer.png" alt="" />欢迎来到找包装网!
        </div>
        <div class="btns" v-if="!$store.state.access_token">
          <button type="text" @click="toLogin">登录</button>
          <button type="text" class="reg" @click="toRegister">注册</button>
        </div>
        <div class="fastIn" v-else>
          <router-link to="/category" class="item boxShadow transition">
            <img src="~assets/images/homeMeIcon1.png" class="icon" alt="" />
            <p class="name f16 corMain">包装材料</p>
          </router-link>
          <router-link to="/industryService/service" class="item boxShadow transition">
            <img src="~assets/images/homeMeIcon2.png" class="icon" alt="" />
            <p class="name f16 corMain">配套服务</p>
          </router-link>
          <div class="item boxShadow transition" @click="slideToService">
            <img src="~assets/images/homeMeIcon3.png" class="icon" alt="" />
            <p class="name f16 corMain">官方服务</p>
          </div>
          <router-link to="/require" class="item boxShadow transition">
            <img src="~assets/images/homeMeIcon4.png" class="icon" alt="" />
            <p class="name f16 corMain">发布需求</p>
          </router-link>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { swiper, swiperSlide } from "vue-awesome-swiper"
import "swiper/dist/css/swiper.css"

export default {
  name: "HomeSwiper",
  components: {
    swiper,
    swiperSlide
  },
  props: {
    banner: Array
  },
  data() {
    return {
      bannerSwi: {
        slidesPerView: 1,
        observeParents: true,
        observer: true,
        autoplay: true,
        pagination: {
          el: ".panel-paginationh",
          clickable: true
        }
      }
    }
  },
  methods: {
    slideToService() {
      window.scrollTo({
        //滚动到元素位置
        top: 3200,
        behavior: "smooth" // 平滑滚动
      })
    },
    viewDetail(url) {
      window.location.href = url;
    },
    toLogin() {
      this.$router.push({
        path: "/login-register/login"
      })
    },
    toRegister() {
      this.$router.push({
        path: "/login-register/register"
      })
    }
  }
}
</script>

<style scoped>
.homeswiper {
  width: 100%;
  height: 550px;
  position: relative;
}

.my-swipe img {
  width: 100%;
  height: 550px;
  object-fit: cover;
  cursor: pointer;
}

.loginBox {
  width: 1200px;
  height: 400px;
  position: absolute;
  top: 0;
  left: 50%;
  margin-left: -600px;
}

.login {
  width: 321px;
  height: 380px;
  color: #e38b2e;
  background: rgba(255, 255, 255, 0.8);
  transform: translateY(-50%);
  text-align: center;
  position: absolute;
  right: 0;
  top: 230px;
  z-index: 99;
}

.login .weclome {
  font-size: 18px;
  font-weight: bold;
  margin-top: 84px;
}
.login .weclome.isLoad {
  margin-top: 50px;
  margin-bottom: 10px;
}
.login .weclome img {
  width: 17px;
  height: 25px;
  vertical-align: top;
}

.login button {
  width: 234px;
  height: 35px;
  line-height: 35px;
  color: #fff;
  background: #e38b2e;
  margin-top: 48px;
  border-radius: 10px;
  cursor: pointer;
}

.login button:hover {
  opacity: 0.9;
  color: #fff;
  background: #e38b2e;
}

.login .reg {
  margin-top: 39px;
  color: #e38b2e;
  background: #fff;
  border: 1px solid #e38b2e;
}
.fastIn {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}
.fastIn .item {
  width: 110px;
  height: 110px;
  display: flex;
  align-content: center;
  justify-content: center;
  line-height: 1.8;
  margin: 10px;
  flex-wrap: wrap;
  cursor: pointer;
  background: #fff;
}
.fastIn .item .icon {
  width: 50px;
  height: 50px;
}
.fastIn .item:hover {
  opacity: 0.8;
}
.panel-paginationh {
  position: absolute;
  bottom: 5%;
  left: 50%;
  z-index: 99;
  transform: translateX(-50%);
}

.panel-paginationh /deep/ .swiper-pagination-bullet {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 16px;
  background: #ccc;
  opacity: 1;
  outline: none;
}

.panel-paginationh /deep/ .swiper-pagination-bullet-active {
  background: rgba(228, 139, 44, 0.9);
  box-shadow: 0 0 10px rgba(228, 139, 44, 0.9);
}
</style>
